<template>
	<view class="addsite">
		<view>
			<view>
				<view>收货人</view>
				<view><input type="text" value="" placeholder="名字" /></view>
			</view>
			<view>
				<view>手机号</view>
				<view><input type="number" value="" placeholder="手机号" /></view>
			</view>
			<view>
				<view>选择地区</view>
				<view>
					<pickerAddress @change="change">{{txt}}</pickerAddress>
				</view>
			</view>
			<view>
				<view>详细地址</view>
				<view><input type="text" value="" placeholder="小区名称" /></view>
			</view>
		</view>
		<view class="site">
			<u-button type="warning" @click="add">保存</u-button>
		</view>
	</view>

</template>

<script>
	import pickerAddress from '../../components/pickerAddress/pickerAddress.vue'
	components: {
		pickerAddress
	}
	export default {
		data() {
			return {
				txt: '选择地址',
				title: 'Hello'
			}
		},
		methods: {
			change(data) {
				this.txt = data.data.join('')
				console.log(data.data.join(''))
			},
			add() {
				uni.navigateTo({
					url: '/my/site/site',
				});
			}
		}
	}
</script>

<style>
	.addsite>view {
		width: 90%;
		margin: 0 auto;
	}

	.addsite>view>view {
		margin-top: 20rpx;
		display: flex;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 36rpx;
	}

	.addsite>view>view>view:nth-child(1) {
		width: 25%;
	}

	.addsite>view>view>view:nth-child(2) {
		margin-left: 5%;
		width: 70%;
	}

	input {
		height: 100rpx;
		line-height: 100rpx;
	}
</style>
<template>
	<view class="addsite">
		<view>
			<view>
				<view>收货人</view>
				<view><input type="text" v-model="receiver" :placeholder="receiver" /></view>
			</view>
			<view>
				<view>手机号</view>
				<view><input type="number" v-model="mobile" :placeholder="mobile" /></view>
			</view>
			<view>
				<view>选择地区</view>
				<view>
					<pickerAddress @change="change">{{txt}}</pickerAddress>
				</view>
			</view>
			<view>
				<view>详细地址</view>
				<view><input type="text" v-model="addr" :placeholder="addr" /></view>
			</view>
		</view>
		<view class="site">
			<u-button type="warning" @click="add">保存</u-button>
		</view>
	</view>

</template>

<script>
	import pickerAddress from '../../components/pickerAddress/pickerAddress.vue'
	components: {
		pickerAddress
	}
	export default {
		data() {
			return {
				txt: '选择地址',
				title: 'Hello',
				mobile: '', //手机号
				receiver: '', //名字
				addr: '', //详细地址,
				province: '', //省份
				city: '', //市
				district: '', //区
				addrId:''
			}
		},
		onLoad(options) { //传入的参数名称，可自行修改
			var data = JSON.parse(options.value); // 字符串转对象
			console.log(data)
			console.log(options.value)
			this.mobile = data.mobile
			this.receiver = data.receiver
			this.addr = data.addr
			this.addrId = data.addrId
			let txt = data.province + data.city + data.area
			console.log(txt)
			this.txt = txt
			//this.leadobj(上个页面传过来的对象名称，即？后面的那个名称) = JSON.parse(decodeURIComponent(options.leadobj));   
		},
		methods: {
			change(data) {
				console.log(this.province = data.data[0])
				console.log(this.city = data.data[1])
				console.log(this.district = data.data[2])
				console.log(this.txt = data.data.join(''))

			},
			add() {
				let {
					receiver,
					mobile,
					addr,
					province,
					city,
					district,
					addrId
				} = this
				this.$u.put('/p/address/updateAddr', {
					province: province,
					city: city,
					area: district,
					addr: addr,
					mobile: mobile,
					receiver: receiver,
					addrId:addrId
				}).then(res => {
					uni.navigateTo({
						url: '/my/site/site',
					});
				}).catch((e) => {})
				uni.navigateTo({
					url: '/my/site/site',
				});
			}
		}
	}
</script>

<style>
	.addsite>view {
		width: 90%;
		margin: 0 auto;
	}

	.addsite>view>view {
		margin-top: 20rpx;
		display: flex;
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 36rpx;
	}

	.addsite>view>view>view:nth-child(1) {
		width: 25%;
	}

	.addsite>view>view>view:nth-child(2) {
		margin-left: 5%;
		width: 70%;
	}

	input {
		height: 100rpx;
		line-height: 100rpx;
	}
</style>
